package com.example.mapper;

import com.example.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 操作user相关数据接口
 */
@Mapper
public interface UserMapper {

    /**
     * 新增
     */
    int insert(User user);

    /**
     * 删除
     */
    @Delete("delete from user where uid = #{id}")
    int deleteById(Integer id);

    /**
     * 修改
     */
    int updateByUId(User user);

    /**
     * 根据ID查询
     */
    @Select("select * from user where uid = #{id}")
    User selectById(Integer id);

    /**
     * 查询所有
     */
    List<User> selectAll();

    /**
     * 根据username查询
     * @param username
     * @return
     */
    @Select("select uid,username,password,name,avatar,role,phone,address from user where username = #{username}")
    User selectByUsername(String username);

    /**
     * 根据uid更新头像
     * @param uid 用户id
     * @param avatarUrl 头像地址
     * @return 影响行数
     */
    @Update("update user set avatar = #{avatarUrl} where uid = #{uid}")
    int updateAvatarByUid(@Param("uid") Integer uid, @Param("avatarUrl") String avatarUrl);

}